<%@page import="isquirrel.beans.Friend"%>
<%@page import="isquirrel.util.HibernateUtil"%>
<%@page import="java.util.Vector" %>
<%@page import="isquirrel.UserManager"%>
<%@page import="isquirrel.beans.Url"%>


<div style="margin-bottom:12px;font-weight: bold; color: rgb(114, 114, 114);">Your friends.</div>
<%	
	String r = request.getRequestURI().split("/")[1];
%>	
<%
	Vector<Friend> friends = (Vector<Friend>) session.getAttribute("friends");
	HibernateUtil.beginTransaction();
	if (friends.size() < 1){
		out.print("<p style='font-size:1em; color: #bbb'>You haven't got any friends.<br><br> <a style='font-weight:bold;font-size:1.4em;color:white;text-decoration:none; padding:3px; background-color:#A5C97F' href='/" +  r + "/servlet/Profiler?nextp=network&force=findfriends'>Find friends</a></p>");
		return;
	}
	else{
		out.print("<p><a style='margin-bottom:12px;font-weight:bold;font-size:1.4em;color:white;text-decoration:none; padding:3px; background-color:#A5C97F' href='/" +  r + "/servlet/Profiler?nextp=home&force=whatyourfriendslike'>Discover what your friends like!</a></p>");
		out.print("<div style='margin-bottom:12px;font-weight: bold; color: rgb(114, 114, 114);'>Friends list.</div>");
		for (Friend f : friends){
			if (f != null) {
				out.print("<div style='height:56px' id='" + f.getUserID() + "' class='friendcontainer'>" +
			        "<img class='friendimg' src='"  + f.getPic() + "' />" +
			        "<div style='width:85%' class='frienddetails'>" + 
			        "<div style='font-weight:bold' class='friendname'>" +
			   		   f.getName() +
			   		"<span class='stopfollow' onClick='stopfollow(this," + f.getUserID() + ");'>Remove from friends</span>"+
			        "</div>" +
			        "<div style='margin-bottom:2px'>" +
			           "Liked " + f.getLikes() + " pages." + 
			        "</div>" +
			        "<div style='margin-bottom:1px'>" +
						"Profile match: " + f.getProfileMatch_formatted() +											        
			        "</div>" +
				     "</div>" +
				  "</div>");
			}
		}
	}
%>

<script type="text/javascript">

	stopfollow = function(spanelem,friend_id) {
		spanelem.update("Removing..");
		new Ajax.Request( 'servlet/RemoveFriend', {
			method: 'post',
			parameters: {
		 				'friend_id': friend_id
			 		} ,  
	  		onComplete: function(transport) {
	 				  	var response = transport.responseText.evalJSON();
	 				  	if (response.error == 0) {

							$(response.friend_id).fade({duration: 0.5});
							
	 				  	}
	 				  	
	 				}
			});
			};

</script>



